<template>
	<section>
		<el-form ref="applyForm" :model="settingAlertForm" label-width="120px" class="setting-alert-form">
			<el-form-item label="提示类型">
				<el-radio class="radio" v-model="settingAlertForm.AlertWay" label="1">提示一次</el-radio>
				<el-radio class="radio" v-model="settingAlertForm.AlertWay" label="2">一直提示</el-radio>
				<el-button type="primary" size="small" @click="fnUpdateAlertWay" style="margin-left: 30px;">确认修改</el-button>
			</el-form-item>

			<el-form-item label="提示音频">
				<!--提示音-->
				<audio :src="voice" controls></audio>

				<el-upload action="/api/setting/alert/voice" :on-success="fnSuccess">
					<el-button size="small" type="primary">上传提示音</el-button>
				</el-upload>
			</el-form-item>
		</el-form>
	</section>
</template>

<script>
    import Svc from '../../service/index.js'
    import moment from 'moment'
	export default {
		data() {
			return {
                settingAlertForm : {
                    AlertWay : 0
				},
                voice:"/api/setting/alert/voice?t="+new Date().getTime()
//				voice:"http://139.224.105.61:9999/api/setting/alert/voice?t="+new Date().getTime()
			}
		},
		methods: {
            //显示message提示框
            openMessage : function(msg,type){
                this.$message({
                    showClose: true,
                    message: msg,
                    type: type
                });
            },
            // 获取原有提示音播放方式
            fnGetAlertWay(){
                var that = this
                Svc.fnGetData('/api/setting/alert',{},function(res){
                    if (res.body.ErrCode == 0){
                        that.settingAlertForm.AlertWay = res.body.Data.AlertWay.toString()
                    } else {
                        that.openMessage("提示音获取失败！",'error')
                    }
                },function(){
                    that.openMessage("网络错误，请重新！",'error')
                })
			},
			// 修改提示音播放方式
            fnUpdateAlertWay(){
                var that = this
				var params = {
                    ID : 1,
                    AlertWay : parseInt(that.settingAlertForm.AlertWay)
            }
                Svc.fnPostData('/api/setting/alert',params,function(res){
                    if (res.body.ErrCode == 0){
                        that.openMessage("提示类型修改成功！",'success')
                    } else {
                        that.openMessage("提示音修改失败！",'error')
                    }
                },function(){
                    that.openMessage("网络错误，请重新！",'error')
                })
			},
			// 上传成功
            fnSuccess(){
                this.openMessage("新提示音上传成功！ ",'success')
                this.voice = "/api/setting/alert/voice?t="+new Date().getTime()
//				this.voice = "http://139.224.105.61:9999/api/setting/alert/voice?t="+new Date().getTime()
			}
		},
		mounted() {
		    // 获取原有提示音
			this.fnGetAlertWay()
		}
	}

</script>

<style scoped>
	.setting-alert-form {
		margin:20px;
		width:70%;
		min-width:600px;
	}
</style>